package com.zhao.dao.secondary;

import com.zhao.entity.secondary.Employee;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.stereotype.Component;

@Mapper
@Component
public interface EmployeeDao{

	//插入
	@InsertProvider(type = SqlProvider.class,method = "insert")
	Integer insert(Employee record);

	//更新
	@UpdateProvider(type = SqlProvider.class,method = "update")
	Integer update(Employee record);

	//删除
	@DeleteProvider(type = SqlProvider.class,method = "delete")
	Integer delete(Employee record);

	class SqlProvider{

		public static String insert(final Employee record){
			return new SQL(){{
				INSERT_INTO("EMPLOYEE");
				VALUES("Id", "#{id}");
				VALUES("Salary", "#{salary}");
			}}.toString();
		}

		public static String update(final Employee record){
			return new SQL(){{
				UPDATE("EMPLOYEE");
				if(record.getSalary()!=null){
					SET("Salary=#{salary}");
				}
				WHERE("Id=#{id}");
			}}.toString();
		}

		public static String delete(final Employee record){
			return new SQL(){{
				DELETE_FROM("EMPLOYEE");
				WHERE("Id=#{id}");
			}}.toString();
		}
	}

}